
/**
* @file      main.c
* @author    Piyumal Ranawaka st20000427
* @version   0.1
* @date      November 15, 2014
* @brief     Overall main method of the weather monitering system
*/

/* Includes -----------------------------------------------------------------------*/
#include "alarm.h"
#include "humidity.h"
#include "I2CDriver.h"
#include "light_intensity.h"
#include "pressure.h"
#include "temperature_sensor.h"
#include "USART.h"


/* Private types ------------------------------------------------------------------*/
/* Private constants --------------------------------------------------------------*/
/* Private macro ------------------------------------------------------------------*/
/* Private variables --------------------------------------------------------------*/
uint16_t pressure_val;
uint16_t temperature_val;
uint16_t humidity_val;
uint16_t light_val;

//data point storage
uint16_t value_array[10][4];

/* Private function prototypes ----------------------------------------------------*/
/* Private functions --------------------------------------------------------------*/




int main()
	{
		//initial hardware configuration done only once after powered on 
		temperature_config();
		pressure_config();
		humidity_config();
		light_intensity_config();
		alarm_config();
		lcd_config();
		SIC4310_config();
		
		while(1){

			//data points are stored in a 10x4 matrix with each row representing temperature,pressure,humidity,light in order.
			//A maximum of 10 data samples taken at every 5s stored due to the limitation of memory and timer but it could be extended to store many points over a long period like for month taken at each hour.

			
			int x; // array index paramets for rows
			int y; // array index parameters for columns upto a maximum of 10 due to limited memory
			
    /* The loop goes while x < 10, and x increases by one every loop*/
     for ( x = 0; x < 9; x++ ){
		
			 //reading values at each 5s for a maximum of 10 points.
			  pressure_val=pressure_read();
				temperature_val=temperature_read();
				humidity_val=humidity_read();
				light_val=light_intensity_read();
				dealy(5000);
			 
			 
				//store values in array
				//In a real application points should be stored against real time obtained from a RTC
				value_array[x][0]=pressure_val;
				value_array[x][1]=temperature_val;
				value_array[x][2]=humidity_val;
				value_array[x][3]=light_intensity_val;	

				
			 
			 //generating alarms when ponts are beyond ambient range
			 
			 if (pressure_val<0.9|pressure_val>1.1){
			 led_blink(0);
			 }
			 
			 if (temperature_val<20|temp_val>32){
			 led_blink(1);
			 }
			 
			 if (humidity_val<40|humidity_val>60){
			 led_blink(2);			 
			 }
			 
			 if (light_val<25|light_val>70){
			 led_blink(3);
			 }
			 
			 						
			}
		
		// lcd_write and SIC4310_write are two methods which could write a complete array sequntially one point after other based on a loop and would write one data point at a time.	
		lcd_write(value_array);
			
			
		//checks wether a capture avaiable at NFC
			boolen NFC_have=SIC4310_available();
				if (NFC_have==1){
					
					
				//lcd_write and SIC4310_write are two methods which could write a complete array sequntially one point after other based on a loop and would write one data point at a time.	
					SIC4310_write(value_array)
				}
				
				
				
				
		}
			
			
          
    }
}


